package com.sajus.billing.client.dto;

import java.io.Serializable;
import java.sql.Time;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;

import javax.naming.NamingException;

import com.sajus.billing.client.delegate.BusinessDelegateFactory;


public class AccountDTO implements Serializable {
	
	private Integer id;
	private String currency;
	private String email;
	private String province;
	private String phone;
	private String company;
	private String streetAddress;
	private boolean addressSameOnCreditCard;
	private String passwordRecoveryQ1Answer;
	private String passwordRecoveryQ2;
	private String postalCode;
	private String city;
	private String firstName;
	private String passwordRecoveryQ2Answer;
	private String passwordRecoveryQ1;
	private String lastName;
	private String country;
	private String county;
	private String streetAddress2;
	private String password;
	private String billingPeriodType;
	private int billingPeriodStartDay;
	private Time billingPeriodStartTime;
	private int billingDay;
	private Time billingTime;
	private Date nextBillingDate;
	private Date subscriptionDate;
	private Date cancellationDate;
	private int status;
	private int type;
	private String transactionReference;
	private String promoCode;
	private PromotionDTO promotion;
	private boolean payByCreditCard;
	private boolean mailInvoice;
	private boolean emailInvoice;
	
	private List<AccountDTO> childrenAccounts;
	
	private Set<ServiceDTO> services;
	private Set<AccountAttributeDTO> accountAttributes;
	
	private List<ServiceDTO> recurring;
	private List<UsageItemLineDTO> usage;
	
	private AccountDTO parent;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getCurrency() {
		return currency;
	}

	public void setCurrency(String currency) {
		this.currency = currency;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getProvince() {
		return province;
	}

	public void setProvince(String province) {
		this.province = province;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getCompany() {
		return company;
	}

	public void setCompany(String company) {
		this.company = company;
	}

	public String getStreetAddress() {
		return streetAddress;
	}

	public void setStreetAddress(String streetAddress) {
		this.streetAddress = streetAddress;
	}

	public boolean isAddressSameOnCreditCard() {
		return addressSameOnCreditCard;
	}

	public void setAddressSameOnCreditCard(boolean addressSameOnCreditCard) {
		this.addressSameOnCreditCard = addressSameOnCreditCard;
	}

	public String getPasswordRecoveryQ1Answer() {
		return passwordRecoveryQ1Answer;
	}

	public void setPasswordRecoveryQ1Answer(String passwordRecoveryQ1Answer) {
		this.passwordRecoveryQ1Answer = passwordRecoveryQ1Answer;
	}

	public String getPasswordRecoveryQ2() {
		return passwordRecoveryQ2;
	}

	public void setPasswordRecoveryQ2(String passwordRecoveryQ2) {
		this.passwordRecoveryQ2 = passwordRecoveryQ2;
	}

	public String getPostalCode() {
		return postalCode;
	}

	public void setPostalCode(String postalCode) {
		this.postalCode = postalCode;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getPasswordRecoveryQ2Answer() {
		return passwordRecoveryQ2Answer;
	}

	public void setPasswordRecoveryQ2Answer(String passwordRecoveryQ2Answer) {
		this.passwordRecoveryQ2Answer = passwordRecoveryQ2Answer;
	}

	public String getPasswordRecoveryQ1() {
		return passwordRecoveryQ1;
	}

	public void setPasswordRecoveryQ1(String passwordRecoveryQ1) {
		this.passwordRecoveryQ1 = passwordRecoveryQ1;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public String getCounty() {
		return county;
	}

	public void setCounty(String county) {
		this.county = county;
	}

	public String getStreetAddress2() {
		return streetAddress2;
	}

	public void setStreetAddress2(String streetAddress2) {
		this.streetAddress2 = streetAddress2;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getBillingPeriodType() {
		return billingPeriodType;
	}

	public void setBillingPeriodType(String billingPeriodType) {
		this.billingPeriodType = billingPeriodType;
	}

	public int getBillingPeriodStartDay() {
		return billingPeriodStartDay;
	}

	public void setBillingPeriodStartDay(int billingPeriodStartDay) {
		this.billingPeriodStartDay = billingPeriodStartDay;
	}

	public Time getBillingPeriodStartTime() {
		return billingPeriodStartTime;
	}

	public void setBillingPeriodStartTime(Time billingPeriodStartTime) {
		this.billingPeriodStartTime = billingPeriodStartTime;
	}

	public int getBillingDay() {
		return billingDay;
	}

	public List<ServiceDTO> getRecurring() {
		return recurring;
	}

	public void setRecurring(List<ServiceDTO> recurring) {
		this.recurring = recurring;
	}

	public List<UsageItemLineDTO> getUsage() {
		return usage;
	}

	public void setUsage(List<UsageItemLineDTO> usage) {
		this.usage = usage;
	}

	public void setBillingDay(int billingDay) {
		this.billingDay = billingDay;
	}

	public Time getBillingTime() {
		return billingTime;
	}

	public void setBillingTime(Time billingTime) {
		this.billingTime = billingTime;
	}

	public Date getNextBillingDate() {
		return nextBillingDate;
	}

	public void setNextBillingDate(Date nextBillingDate) {
		this.nextBillingDate = nextBillingDate;
	}

	public Date getSubscriptionDate() {
		return subscriptionDate;
	}

	public void setSubscriptionDate(Date subscriptionDate) {
		this.subscriptionDate = subscriptionDate;
	}

	public Date getCancellationDate() {
		return cancellationDate;
	}

	public void setCancellationDate(Date cancellationDate) {
		this.cancellationDate = cancellationDate;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public String getTransactionReference() {
		return transactionReference;
	}

	public void setTransactionReference(String transactionReference) {
		this.transactionReference = transactionReference;
	}

	public String getPromoCode() {
		return promoCode;
	}

	public void setPromoCode(String promoCode) {
		this.promoCode = promoCode;
	}

	public PromotionDTO getPromotion() {
		return promotion;
	}

	public void setPromotion(PromotionDTO promotion) {
		this.promotion = promotion;
	}

	public boolean isPayByCreditCard() {
		return payByCreditCard;
	}

	public void setPayByCreditCard(boolean payByCreditCard) {
		this.payByCreditCard = payByCreditCard;
	}

	public boolean isMailInvoice() {
		return mailInvoice;
	}

	public void setMailInvoice(boolean mailInvoice) {
		this.mailInvoice = mailInvoice;
	}

	public boolean isEmailInvoice() {
		return emailInvoice;
	}

	public void setEmailInvoice(boolean emailInvoice) {
		this.emailInvoice = emailInvoice;
	}

	public List<AccountDTO> getChildrenAccounts() {
		return childrenAccounts;
	}

	public void setChildrenAccounts(List<AccountDTO> childrenAccounts) {
		this.childrenAccounts = childrenAccounts;
	}

	public Set<ServiceDTO> getServices() {
		return services;
	}

	public void setServices(Set<ServiceDTO> services) {
		this.services = services;
	}

	public Set<AccountAttributeDTO> getAccountAttributes() {
		return accountAttributes;
	}

	public void setAccountAttributes(Set<AccountAttributeDTO> accountAttributes) {
		this.accountAttributes = accountAttributes;
	}

	public List<UsageDataDTO> getUsageDataList(){
		List<UsageDataDTO> ret;
		try {
			ret = BusinessDelegateFactory.getInstance().getAccountManager().getUsageDataList( this );
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			return null;
		}
		return ret;
	}
	
	public double getUsageTotal(){
		List<UsageDataDTO> usageList = getUsageDataList();
		double sum = 0d;
		for ( UsageDataDTO usage : usageList ){
			sum =+ usage.getCharge();
		}
		
		return sum;
	}

	public AccountDTO getParent() {
		return parent;
	}

	public void setParent(AccountDTO parent) {
		this.parent = parent;
	}

}
